exports.install = function (Vue) {
  Vue.prototype.text1 = function () {//全局函数1
    alert('执行成功1');
  };
  //退出登录
  Vue.prototype.exitLogin = function () {
    localStorage.clear();
    sessionStorage.clear();
    window.location.reload()
  };
  //转化年月日
  Vue.prototype.dateTimeManage = function (date) {
    if (isNaN(date)) return date;
    date = date * 1000;
    date = new Date(date);
    var y = date.getFullYear();
    var M = date.getMonth() + 1;
    M = M < 10 ? ('0' + M) : M;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    parseInt(h) < 10 ? h = '0' + h : h = h;
    var m = date.getMinutes();
    parseInt(m) < 10 ? m = '0' + m : m = m;
    var s = date.getSeconds();
    parseInt(s) < 10 ? s = '0' + s : s = s;
    return y + '-' + M + '-' + d + ' ' + h + ':' + m + ':' + s;
  };
//  按钮权限加密
  Vue.prototype.encryptButton = function (word) {
    var key = this.CryptoJS.enc.Utf8.parse("%$#@zjt94217@#$%");
    var srcs = this.CryptoJS.enc.Utf8.parse(word);
    var encrypted = this.CryptoJS.AES.encrypt(srcs, key, {
      mode: this.CryptoJS.mode.ECB,
      padding: this.CryptoJS.pad.Pkcs7
    });
    return encrypted.toString();
  };
  //  按钮权限解密
  Vue.prototype.edecryptButton = function (word) {
    var key = this.CryptoJS.enc.Utf8.parse("%$#@zjt94217@#$%");
    var decrypt = this.CryptoJS.AES.decrypt(word, key, {
      mode: this.CryptoJS.mode.ECB,
      padding: this.CryptoJS.pad.Pkcs7
    });
    return this.CryptoJS.enc.Utf8.stringify(decrypt).toString();
  };
//生成签名并假面Aes加密
  Vue.prototype.encryptionAesRsa = function (data) {
    var keysArr = [], sign_, $salt = "%$#@waifang@#$%", signstr, $sign;
    data.timestamp = Date.parse(new Date()) / 1000;
    data.version = this.GLOBAL.Version;
    for (var keya in data) {
      keysArr.push(keya + '=' + data[keya]);
    }
    keysArr.sort();
    sign_ = keysArr.join('&');
    signstr = this.$md5($salt + this.$md5(sign_) + $salt);
    $sign = signstr.substr(0, 4) + signstr.substr(-5, 5);
    data.sign = $sign;
    var dataArr = data;
    var keysArr2 = [];
    for (var k in dataArr) {
      keysArr2.push(k + '=' + dataArr[k]);
    }
    keysArr2.sort();
    var sign_arr = keysArr2.join('&');

    function randomWord(randomFlag, min, max) {
      var str = "",
        range = min,
        arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
      // 随机产生
      if (randomFlag) {
        range = Math.round(Math.random() * (max - min)) + min;
      }
      for (var i = 0; i < range; i++) {
        pos = Math.round(Math.random() * (arr.length - 1));
        str += arr[pos];
      }
      return str;
    }

    function rsafn(words) {
      var encrypt = new JSEncrypt();
      encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdsDAy7Wdd+/SAhXZxA6v+adw5Hqk5SHRStpWINlBfhyKq9OXZyszlw9d6ezxphbxhZVNqNozQQNl+kB5XoZwA2lZn7g2RujtOFd9aG8Fp92hFMcfP/yTEEm4AwpSyBQHTAajjSqQCm2OHuHDIfyXUE/BTgTSVR2W2Mx0O6oBb+wIDAQAB-----END PUBLIC KEY-----');
      var encrypty = encrypt.encrypt(words);
      encrypty = encrypty.replace(/\+/g, "-");
      encrypty = encrypty.replace(/\//g, "_");
      encrypty = encrypty.replace(/\=/g, "");
      return encrypty
    }

    var keys = randomWord(false, 16);
    var key = this.CryptoJS.enc.Utf8.parse(keys);
    var srcs = this.CryptoJS.enc.Utf8.parse(sign_arr);
    var encrypted = this.CryptoJS.AES.encrypt(srcs, key, {
      mode: this.CryptoJS.mode.ECB,
      padding: this.CryptoJS.pad.Pkcs7
    });
    return encrypted.toString() + '%$#@zjt@#$%' + rsafn(keys);
  };
// 请求回调函数
  Vue.prototype.plumAxios = function (url, data, callBackDone) {
    let str = this.encryptionAesRsa(data);
    let encryptData = str.split('%$#@zjt@#$%')[0];
    let encryptKey = str.split('%$#@zjt@#$%')[1];
    let incomData = {
      map: url,
      plum_session_api: localStorage.getItem('token'),
      encryptData: encryptKey,
      encryptKey: encryptData
    };
    this.$http.post('', incomData).then((ret) => {
      callBackDone(ret)
    }).catch((err) => {
      this.$message.error('error!');
    })
  };
};
